home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / demo / demosrc / d_matrix.pro < prev    next >
Text File  |  1997-07-08  |  24KB  |  747 lines

  1. ;$Id: d_matrix.pro,v 1.14 1997/04/18 22:48:11 tremblay Exp $
  2. ;
  3. ;  Copyright (c) 1997, Research Systems, Inc. All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5. ;
  6. ;+
  7. ;  FILE:
  8. ;       d_matrix.pro
  9. ;
  10. ;  CALLING SEQUENCE: d_matrix
  11. ;
  12. ;  PURPOSE:
  13. ;       This demo shows the various plots in IDL made from 2-D data.
  14. ;
  15. ;  MAJOR TOPICS: Data analysis and plotting
  16. ;
  17. ;  CATEGORY:
  18. ;       IDL 5.0
  19. ;
  20. ;  INTERNAL FUNCTIONS and PROCEDURES:
  21. ;       pro mat_Generate            -  Generate the 2-D data set
  22. ;       pro mat_MakePlot            -  Make 5 plots to pixmaps.
  23. ;       pro D_Matrix_Event            -  Event handler
  24. ;       pro D_Matrix_Cleanup          -  Cleanup
  25. ;       pro D_Matrix                  -  Main procedure
  26. ;
  27. ;  EXTERNAL FUNCTIONS, PROCEDURES, and FILES:
  28. ;       matrix.txt
  29. ;       matrix.tip
  30. ;       pro gettips                 -  Get the tip text
  31. ;       pro widtips                 -  Create the widget text for tips
  32. ;       pro sizetips                -  Size the widget text for tips
  33. ;
  34. ;  REFERENCE: IDL Reference Guide, IDL User's Guide
  35. ;
  36. ;  NAMED STRUCTURES:
  37. ;       none.
  38. ;
  39. ;  COMMON BLOCS:
  40. ;       none.
  41. ;
  42. ;  MODIFICATION HISTORY:
  43. ;       95,   Dan Carr   - Written.
  44. ;       11/95,   DAT     - Modified for IDL 5.0 demo
  45. ;-
  46. ; -----------------------------------------------------------------------------
  47. ;
  48. ;  Purpose:  Generate a new data set
  49. ;
  50. pro mat_Generate, $
  51.     xArray, $       ; OUT: x coordinates 
  52.     yArray, $       ; OUT: y coordinates
  53.     height, $       ; OUT: height data point 
  54.     xVelocity, $    ; OUT: x velocity vector
  55.     yVelocity       ; OUT: y velocity vector
  56.  
  57.     xVelocity = FLTARR(94, 78)
  58.     yVelocity = FLTARR(94, 78)
  59.     xArray = FLTARR(80)
  60.     yArray = FLTARR(64)
  61.  
  62.     xVelocity = RANDOMN(seed, 94, 78)
  63.     yVelocity = RANDOMN(seed, 94, 78)
  64.  
  65.     xVelocity = SMOOTH(xVelocity, 3)
  66.     xVelocity = SMOOTH(xVelocity, 3)
  67.     xVelocity = SMOOTH(xVelocity, 7)
  68.     xVelocity = SMOOTH(xVelocity, 7)
  69.     xVelocity = SMOOTH(xVelocity, 3)
  70.     xVelocity = SMOOTH(xVelocity, 3)
  71.  
  72.     yVelocity = SMOOTH(yVelocity, 3)
  73.     yVelocity = SMOOTH(yVelocity, 3)
  74.     yVelocity = SMOOTH(yVelocity, 7)
  75.     yVelocity = SMOOTH(yVelocity, 7)
  76.     yVelocity = SMOOTH(yVelocity, 3)
  77.     yVelocity = SMOOTH(yVelocity, 3)
  78.  
  79.     xVelocity = xVelocity(7:86, 7:70)
  80.     yVelocity = yVelocity(7:86, 7:70)
  81.  
  82.     height = SQRT((xVelocity * xVelocity) + (yVelocity * yVelocity))
  83.     xArray = FINDGEN(80) / 79.0
  84.     yArray = FINDGEN(64) / 63.0
  85.  
  86. end     ;  of mat_Generate
  87.  
  88. ; -----------------------------------------------------------------------------
  89. ;
  90. ;  Purpose:  Make the plots
  91. ;
  92. pro mat_makePlot, $
  93.     pixmapArray, $     ; IN: array of 7 pixmaps
  94.     xArray,  $         ; IN; x data
  95.     yArray, $          ; IN; y data
  96.     height, $          ; IN; z data
  97.     xVelocity, $       ; IN; velocity along x (for velocity plot)
  98.     yVelocity, $       ; IN; velocity along y (for velocity plot)
  99.     drawXSize, $       ; IN; x size of drawing area
  100.     drawYSize, $       ; IN; y size of drawing area
  101.     maxImage, $        ; IN; number of color in the images
  102.     plotPosition       ; IN;  normalized position of the plots
  103.  
  104.     ;  Initialize the position values
  105.     ;
  106.     x0 = 0.175
  107.     y0 = 0.175
  108.     x1 = 0.5375
  109.     y1 = 0.5375
  110.     x2 = 0.9
  111.     y2 = 0.9
  112.  
  113.     ;  First plot is the velocity field
  114.     ;
  115.     WSET, pixmapArray(0)
  116.     ERASE
  117.     previousFont = !P.FONT
  118.     previousColor = !P.COLOR
  119.     !P.FONT = (-1)
  120.     !P.COLOR = maxImage + 3
  121.     VEL, xVelocity, yVelocity, NVECS=500, XMAX=1.0, $
  122.         TITLE=''
  123.     !P.COLOR = previousColor
  124.     !P.FONT = previousFont
  125.  
  126.     XYOUTS, (plotPosition(0)+plotPosition(2))/2.0, $
  127.         (plotPosition(3)+0.03), 'Velocity Field', /NORMAL, $
  128.         ALIGNMENT=0.5, SIZE=(!P.Charsize * 1.25), FONT=0
  129.  
  130.     WSET, pixmapArray(6)
  131.     ERASE
  132.     previousColor = !P.COLOR
  133.     previousFont = !P.FONT
  134.     !P.FONT = (-1)
  135.     !p.color = maxImage + 3
  136.     VEL, xVelocity, yVelocity, NVECS=500, XMAX=1.0, $
  137.         TITLE=''
  138.     !P.COLOR = previousColor
  139.     !P.FONT = previousFont
  140.  
  141.     XYOUTS, (plotPosition(0)+plotPosition(2))/2.0, $
  142.         (plotPosition(3)+0.03), 'Velocity Field', /NORMAL, $
  143.         ALIGNMENT=0.5, SIZE=(!P.Charsize * 1.25), FONT=0
  144.  
  145.     WSET, pixmapArray(5)
  146.     DEVICE, COPY=[ 0, 0, drawXSize/2, drawYSize/2, 0, $
  147.          drawYSize/2, pixmapArray(6)]
  148.  
  149.     ;  Contour plot
  150.     ;
  151.     WSET, pixmapArray(1)
  152.     colorVector = FIX(FLOAT(maxImage) * FINDGEN(8) / 7.0)
  153.     CONTOUR, height, xArray, yArray, NLEVELS=8, C_COLORS=colorVector
  154.     CONTOUR, height, xArray, yArray, /NODATA, /NOERASE
  155.     XYOUTS, (plotPosition(0)+plotPosition(2))/2.0, $
  156.         (plotPosition(3)+0.03), 'Contour', /NORMAL, $
  157.         ALIGNMENT=0.5, SIZE=(!P.Charsize * 1.25), FONT=0
  158.  
  159.     WSET, pixmapArray(6)
  160.     ERASE
  161.     colorVector = FIX(FLOAT(maxImage) * FINDGEN(8) / 7.0)
  162.     CONTOUR, height, xArray, yArray, NLEVELS=8, C_COLORS=colorVector
  163.     CONTOUR, height, xArray, yArray, /NODATA, /NOERASE
  164.     XYOUTS, (plotPosition(0)+plotPosition(2))/2.0, $
  165.         (plotPosition(3)+0.03), 'Contour', /NORMAL, $
  166.         ALIGNMENT=0.5, SIZE=(!P.Charsize * 1.25), FONT=0
  167.  
  168.     WSET, pixmapArray(5)
  169.     DEVICE, COPY=[ 0, 0, drawXSize/2, drawYSize/2, drawXSize/2, $
  170.          drawYSize/2, pixmapArray(6)]
  171.  
  172.     ;  Image plot
  173.     ;
  174.     WSET, pixmapArray(2)
  175.     ERASE
  176.     imagePosition = plotPosition
  177.     imagePosition([0,2]) = FIX(imagePosition([0,2]) * $
  178.         FLOAT(drawXSize))
  179.     imagePosition([1,3]) = FIX(imagePosition([1,3]) * $
  180.         FLOAT(drawYSize))
  181.     image = BYTSCL(CONGRID(height, (imagePosition(2)-imagePosition(0)), $
  182.         (imagePosition(3)-imagePosition(1)), /INTERP), TOP=maxImage)
  183.     TV, image, imagePosition(0), imagePosition(1)
  184.     CONTOUR, height, xArray, yArray, /NODATA, /NOERASE
  185.     XYOUTS, (plotPosition(0)+plotPosition(2))/2.0, $
  186.         (plotPosition(3)+0.03), 'Image', /NORMAL, $
  187.         ALIGNMENT=0.5, SIZE=(!P.Charsize * 1.25), FONT=0
  188.  
  189.     WSET, pixmapArray(6)
  190.     ERASE
  191.     imagePosition = plotPosition
  192.     imagePosition([0,2]) = FIX(imagePosition([0,2]) * $
  193.         FLOAT(drawXSize/2))
  194.     imagePosition([1,3]) = FIX(imagePosition([1,3]) * $
  195.         FLOAT(drawYSize/2))
  196.     image = BYTSCL(CONGRID(height, (imagePosition(2)-imagePosition(0)), $
  197.         (imagePosition(3)-imagePosition(1)), /INTERP), TOP=maxImage)
  198.     TV, image, imagePosition(0), imagePosition(1)
  199.     CONTOUR, height, xArray, yArray, /NODATA, /NOERASE
  200.     XYOUTS, (plotPosition(0)+plotPosition(2))/2.0, $
  201.         (plotPosition(3)+0.03), 'Image', /NORMAL, $
  202.         ALIGNMENT=0.5, SIZE=(!P.Charsize * 1.25), FONT=0
  203.  
  204.     WSET, pixmapArray(5)
  205.     DEVICE, COPY=[ 0, 0, drawXSize/2, drawYSize/2, 0, $
  206.          0, pixmapArray(6)]
  207.  
  208.     ;  Surface plot
  209.     ;
  210.     height2 = CONGRID(height, 20, 16)
  211.     xArray2 = FINDGEN(20)/ 19.0
  212.     yArray2 = FINDGEN(16)/ 15.0
  213.     shadow = BYTSCL(CONGRID((yVelocity-xVelocity), 26, 26, /INTERP), $
  214.         TOP=maxImage)
  215.     previousTicklen = !P.TICKLEN
  216.     !P.TICKLEN=(-0.05)
  217.     previousFont = !P.FONT
  218.     !P.FONT = (-1)
  219.     position = [0.175, 0.175, 0.9, 0.9]
  220.  
  221.     WSET, pixmapArray(3)
  222.     SHADE_SURF, height2, xArray2, yArray2, $
  223.         AX=60, AZ=30, ZRANGE=[-0.25, 0.75], $
  224.         SHADES=shadow, $
  225.         XTICKNAME=[' 0.0',' 0.2',' 0.4',' 0.6',' 0.8',' 1.0'], $
  226.         YTICKNAME=['0.0 ','0.2 ','0.4 ','0.6 ','0.8 ','    ']
  227.     SURFACE, height2, xArray2, yArray2, $
  228.         AX=60, AZ=30, ZRANGE=[-0.25, 0.75], /NOERASE, $
  229.         XTICKNAME=[' 0.0',' 0.2',' 0.4',' 0.6',' 0.8',' 1.0'], $
  230.         YTICKNAME=['0.0 ','0.2 ','0.4 ','0.6 ','0.8 ','    '], $
  231.         SKIRT=(-0.25), COLOR= maxImage+3
  232.     SURFACE, height2, xArray2, yArray2, $
  233.         AX=60, AZ=30, ZRANGE=[-0.25, 0.75], /NOERASE, $
  234.         XTICKNAME=[' 0.0',' 0.2',' 0.4',' 0.6',' 0.8',' 1.0'], $
  235.         YTICKNAME=['0.0 ','0.2 ','0.4 ','0.6 ','0.8 ','    '], $
  236.         SKIRT=(-0.25), /NODATA
  237.     XYOUTS, (position(0)+position(2))/2.0, $
  238.         (position(3)+0.03), 'Shaded Surface', /NORMAL, $
  239.         ALIGNMENT=0.5, SIZE=(!P.Charsize * 1.25), FONT=0
  240.  
  241.  
  242.     WSET, pixmapArray(6)
  243.     ERASE
  244.     SHADE_SURF, height2, xArray2, yArray2, $
  245.         AX=60, AZ=30, ZRANGE=[-0.25, 0.75], $
  246.         SHADES=shadow, $
  247.         XTICKNAME=[' 0.0',' 0.2',' 0.4',' 0.6',' 0.8',' 1.0'], $
  248.         YTICKNAME=['0.0 ','0.2 ','0.4 ','0.6 ','0.8 ','    ']
  249.     SURFACE, height2, xArray2, yArray2, $
  250.         AX=60, AZ=30, ZRANGE=[-0.25, 0.75], /NOERASE, $
  251.         XTICKNAME=[' 0.0',' 0.2',' 0.4',' 0.6',' 0.8',' 1.0'], $
  252.         YTICKNAME=['0.0 ','0.2 ','0.4 ','0.6 ','0.8 ','    '], $
  253.         SKIRT=(-0.25), COLOR= maxImage+3
  254.     SURFACE, height2, xArray2, yArray2, $
  255.         AX=60, AZ=30, ZRANGE=[-0.25, 0.75], /NOERASE, $
  256.         XTICKNAME=[' 0.0',' 0.2',' 0.4',' 0.6',' 0.8',' 1.0'], $
  257.         YTICKNAME=['0.0 ','0.2 ','0.4 ','0.6 ','0.8 ','    '], $
  258.         SKIRT=(-0.25), /NODATA
  259.     XYOUTS, (position(0)+position(2))/2.0, $
  260.         (position(3)+0.03), 'Shaded Surface', /NORMAL, $
  261.         ALIGNMENT=0.5, SIZE=(!P.Charsize * 1.25), FONT=0
  262.  
  263.  
  264.     WSET, pixmapArray(5)
  265.     DEVICE, COPY=[ 0, 0, drawXSize/2, drawYSize/2, drawXSize/2, $
  266.          0, pixmapArray(6)]
  267.  
  268.     !P.TICKLEN= previousTicklen
  269.     !P.FONT = previousFont
  270.  
  271.     ;  Get the current color vectors to restore when this application is exited.
  272.     ;
  273.     TVLCT, saveR, saveG, saveB, /GET
  274.  
  275.     ;  Build color table from color vectors.
  276.     ;
  277.     previousTable = [[saveR],[saveG],[saveB]]
  278.  
  279.     ;  Show3 plot.
  280.     ;
  281.     WSET, pixmapArray(4)
  282.     SHOW3, height
  283.  
  284.     ;  Scale the image in order to conform to the color table
  285.     ;
  286.     show3Image = TVRD()
  287.     show3Image = BYTSCL(show3Image, TOP = maxImage-1)
  288.     ERASE
  289.     TV, show3Image
  290.  
  291.     TVLCT, previousTable, 0
  292.  
  293. end     ;   of  mat_makePlot
  294.  
  295. ; -----------------------------------------------------------------------------
  296. ;
  297. ;  Purpose:  Event handler
  298. ;
  299. pro D_Matrix_Event, $
  300.     sEvent     ; IN: event structure
  301.  
  302.     ;  Quit the application using the close box.
  303.     ;
  304.     if (TAG_NAMES(sEvent, /STRUCTURE_NAME) EQ $
  305.         'WIDGET_KILL_REQUEST') then begin
  306.         WIDGET_CONTROL, sEvent.top, /DESTROY
  307.         RETURN
  308.     endif
  309.  
  310.     ;  Get the info structure from top-level base.
  311.     ;
  312.     WIDGET_CONTROL, sEvent.top, GET_UVALUE=sInfo, /NO_COPY
  313.       
  314.     ;  Determine which event.
  315.     ; 
  316.     WIDGET_CONTROL, sEvent.id, GET_UVALUE=eventval
  317.  
  318.     ;  Take the following action based on the corresponding event.
  319.     ;
  320.     case eventval of
  321.  
  322.         "GENERATE": begin
  323.            
  324.             WIDGET_CONTROL, sInfo.wLeftBase, sensitive=0
  325.             WIDGET_CONTROL, sInfo.wFileButton, sensitive=0
  326.             WIDGET_CONTROL, sInfo.wHelpButton, sensitive=0
  327.             
  328.             WSET, sInfo.drawWindowID
  329.             ERASE
  330.             XYOUTS, 0.5, 0.5, /NORMAL, COLOR=sInfo.maxImage+7, $ 
  331.                 ' GENERATING DATA   PLEASE WAIT....', $
  332.                 ALIGNMENT=0.5, SIZE=(!P.Charsize * 6.0), FONT=0
  333.  
  334.             ;  Generate a data set
  335.             ;
  336.             mat_Generate, xArray, yArray, height, xvelocity, yvelocity
  337.  
  338.             mat_makePlot, sInfo.pixmapArray, xArray, yArray, height, $
  339.                 xVelocity, yVelocity, sInfo.drawXSize, sInfo.drawYSize, $
  340.                 sInfo.maxImage, sInfo.plotPosition
  341.  
  342.             ;  Display the 4 plots screen
  343.             ;
  344.             WSET, sInfo.drawWindowID
  345.             DEVICE, COPY=[ 0,0, sInfo.drawXSize, sInfo.drawYSize, 0, $
  346.                  0, sInfo.pixmapArray(5)]
  347.  
  348.             WIDGET_CONTROL, sInfo.wPlotDroplist, SET_VALUE=5
  349.  
  350.             WIDGET_CONTROL, sInfo.wLeftBase, sensitive=1
  351.             WIDGET_CONTROL, sInfo.wFileButton, sensitive=1
  352.             WIDGET_CONTROL, sInfo.wHelpButton, sensitive=1
  353.  
  354.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sInfo, /NO_COPY
  355.  
  356.         end     ;       of GENERATE
  357.  
  358.         "PLOTLIST": begin
  359.  
  360.             case sEvent.Value of
  361.   
  362.                 ;  Velocity field
  363.                 ;
  364.                 0 : begin
  365.                     WSET, sInfo.drawWindowID
  366.                     DEVICE, COPY=[ 0,0, sInfo.drawXSize, $
  367.                         sInfo.drawYSize, 0, $
  368.                         0, sInfo.pixmapArray(0)]
  369.                 end    ;    of 0
  370.  
  371.                 ;  Contour plot
  372.                 ;
  373.                 1 : begin
  374.                     WSET, sInfo.drawWindowID
  375.                     DEVICE, COPY=[ 0,0, sInfo.drawXSize, $
  376.                         sInfo.drawYSize, 0, $
  377.                         0, sInfo.pixmapArray(1)]
  378.                 end    ;    of 1
  379.  
  380.                 ;  Image
  381.                 ;
  382.                 2 : begin
  383.                     WSET, sInfo.drawWindowID
  384.                     DEVICE, COPY=[ 0,0, sInfo.drawXSize, $
  385.                         sInfo.drawYSize, 0, $
  386.                         0, sInfo.pixmapArray(2)]
  387.                 end    ;    of 2
  388.  
  389.                 ;  Shaded Surface plot
  390.                 ;
  391.                 3 : begin
  392.                     WSET, sInfo.drawWindowID
  393.                     DEVICE, COPY=[ 0,0, sInfo.drawXSize, $
  394.                         sInfo.drawYSize, 0, $
  395.                         0, sInfo.pixmapArray(3)]
  396.                 end    ;    of 3
  397.  
  398.                 ;  Show3 plot
  399.                 ;
  400.                 4 : begin
  401.                     WSET, sInfo.drawWindowID
  402.                     DEVICE, COPY=[ 0,0, sInfo.drawXSize, $
  403.                         sInfo.drawYSize, 0, $
  404.                         0, sInfo.pixmapArray(4)]
  405.                 end    ;    of 4
  406.  
  407.                 ;  Show 4  plots (velocity, contour, image, surface)
  408.                 ;
  409.                 5 : begin
  410.                     WSET, sInfo.drawWindowID
  411.                     DEVICE, COPY=[ 0,0, sInfo.drawXSize, $
  412.                         sInfo.drawYSize, 0, $
  413.                         0, sInfo.pixmapArray(5)]
  414.                 end    ;    of 5
  415.  
  416.             endcase     ;  of listValue
  417.  
  418.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sInfo, /NO_COPY
  419.  
  420.         end     ;   of PLOTLIST
  421.  
  422.  
  423.         "ABOUT": begin
  424.         
  425.             if (Xregistered('XDisplayFile') ne 0) then begin
  426.                 ;  Restore the info structure
  427.                 ;
  428.                 WIDGET_CONTROL, sEvent.top, SET_UVALUE=sInfo, /NO_COPY
  429.                 RETURN
  430.             endif
  431.         
  432.             ;  Display the information.
  433.             ;
  434.             XDisplayFile, filepath("matrix.txt", $
  435.                 SUBDIR=['examples','demo','demotext']), $
  436.                 DONE_BUTTON='Done', $
  437.                 TITLE=" Plotting matrices", $
  438.                 GROUP=sEvent.top, WIDTH=55, HEIGHT=14
  439.  
  440.             ;  Restore the info structure
  441.             ;
  442.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sInfo, /NO_COPY
  443.       
  444.         end   
  445.                    
  446.         "QUIT": begin
  447.      
  448.             ;  Restore the info structure before destroying event.top
  449.             ;
  450.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sInfo, /NO_COPY
  451.                    
  452.             ;  Destroy widget hierarchy.
  453.             ;
  454.             WIDGET_CONTROL, sEvent.top, /DESTROY
  455.          
  456.         end
  457.  
  458.         ELSE :  begin
  459.  
  460.             PRINT, 'Case Statement found no matches'
  461.  
  462.             ; Restore the info structure
  463.             ;
  464.             WIDGET_CONTROL, sEvent.top, Set_UValue=info, /No_Copy
  465.         end
  466.  
  467.     endcase
  468.    
  469. end               ; of D_Matrix_Event
  470.  
  471. ; -----------------------------------------------------------------------------
  472. ;
  473. ;  Purpose:  Cleanup procedure
  474. ;
  475. pro D_Matrix_Cleanup, $
  476.     wTopBase      ; IN: top level base associated with the cleanup
  477.  
  478.     ;  Get the color table saved in the window's user value.
  479.     ;
  480.     WIDGET_CONTROL, wTopBase, GET_UVALUE=sInfo,/No_Copy
  481.       
  482.     ;  Restore the previous color table.
  483.     ;
  484.     TVLCT, sInfo.colorTable
  485.    
  486.     ;  Delete the pixmaps.
  487.     ;
  488.     for i = 0, sInfo.nPixmap-1 do begin
  489.         WDELETE, sInfo.pixmapArray(i)
  490.     endfor
  491.    
  492.     ;  Map the group leader base if it exists.
  493.     ;
  494.     if (WIDGET_INFO(sInfo.groupBase, /VALID_ID)) then $
  495.         WIDGET_CONTROL, sInfo.groupBase, /MAP
  496.  
  497. end   ; of CleanupTemplate
  498.  
  499.  
  500. ; -----------------------------------------------------------------------------
  501. ;
  502. ;  Purpose:  Main procedure of the matrix demo
  503. ;
  504. pro D_Matrix, $
  505.     GROUP=group, $     ; IN: (opt) group identifier
  506.     APPTLB = appTLB    ; OUT: (opt) TLB of this application
  507.  
  508.     ; Check the validity of the group identifier
  509.     ;
  510.     ngroup = N_ELEMENTS(group)
  511.     if (ngroup NE 0) then begin
  512.         check = WIDGET_INFO(group, /VALID_ID)
  513.         if (check NE 1) then begin
  514.             print,'Error, the group identifier is not valid'
  515.             print, 'Return to the main application'
  516.             RETURN
  517.         endif
  518.         groupBase = group
  519.     endif else groupBase = 0L
  520.  
  521.     ;  Make the system to have a maximum of 256 colors
  522.     ;
  523.     numcolors = !d.N_COLORS
  524.     if( (( !D.NAME EQ 'X') or (!D.NAME EQ 'MAC')) $
  525.         and (!d.N_COLORS GE 256L)) then $
  526.         DEVICE, PSEUDO_COLOR=8
  527.  
  528.     DEVICE, DECOMPOSED=0, BYPASS_TRANSLATION=0
  529.  
  530.     ;  Get the current color table 
  531.     ;
  532.     TVLCT, savedR, savedG, savedB, /GET
  533.  
  534.     ;  Build color table from color vectors
  535.     ;
  536.     colorTable = [[savedR],[savedG],[savedB]]
  537.  
  538.     LOADCT, 5, /SILENT
  539.     
  540.     ;  Save the currnet position system variables and set a new one
  541.     ;
  542.     previousPosition = !P.Position
  543.     plotPosition = FLTARR(4)
  544.     plotPosition = [0.175, 0.175, 0.9, 0.9]
  545.     !P.Position = plotPosition
  546.  
  547.     ;  Get the character scaling factor
  548.     ;
  549.     charscale = 8.0/!d.X_CH_SIZE
  550.  
  551.     ;  Load a color table, reserve the last 9 colors for annotation
  552.     ;
  553.     LOADCT, 5, /SILENT
  554.  
  555.     maxImage = !D.TABLE_SIZE-9  ;  maximum number of color for plots
  556.  
  557.     ;  Load 8 tek colors, the last color index is the
  558.     ;  one from the original  color table.
  559.     ;
  560.     TEK_COLOR, maxImage, 8        
  561.  
  562.     ;  Determine hardware display size.
  563.     ;
  564.     DEVICE, GET_SCREEN_SIZE = screenSize
  565.  
  566.     ;  Create the starting up message.
  567.     ;
  568.     if (ngroup EQ 0) then begin
  569.         drawbase = startmes()
  570.     endif else begin
  571.         drawbase = startmes(GROUP=group)
  572.     endelse
  573.  
  574.     ;  Get the tips.
  575.     ;
  576.     sText = getTips(filepath('matrix.tip', $
  577.         SUBDIR=['examples','demo', 'demotext']) )
  578.  
  579.     ; Define a main widget base.
  580.     ;
  581.     if (N_ELEMENTS(group) EQ 0) then begin
  582.         wTopBase = WIDGET_BASE(TITLE="Matrix Plotting", /COLUMN, $
  583.             /TLB_KILL_REQUEST_EVENTS, $
  584.             MAP=0, $
  585.             TLB_FRAME_ATTR=1, MBAR=barBase)
  586.     endif else begin
  587.         wTopBase = WIDGET_BASE(TITLE="Matrix Plotting", /COLUMN, $
  588.             /TLB_KILL_REQUEST_EVENTS, $
  589.             MAP=0, $
  590.             GROUP_LEADER=group, $
  591.             TLB_FRAME_ATTR=1, MBAR=barBase)
  592.     endelse
  593.  
  594.         ;  Create the quit button
  595.         ;
  596.         wFileButton = WIDGET_BUTTON(barBase, VALUE= 'File', /MENU)
  597.  
  598.             wQuitButton = WIDGET_BUTTON(wFileButton, $
  599.                 VALUE='Quit', UVALUE='QUIT')
  600.  
  601.         ; Create the help button
  602.         ;
  603.         wHelpButton = WIDGET_BUTTON(barBase, /HELP, $
  604.             VALUE='About', /MENU)
  605.  
  606.             wAboutButton = WIDGET_BUTTON(wHelpButton, $
  607.                 VALUE='About Matrix Plotting', UVALUE='ABOUT')
  608.  
  609.         ;  Create the first child of the top level base
  610.         ; 
  611.         wTopRowBase = WIDGET_BASE(wTopBase, COLUMN=2, /FRAME)
  612.  
  613.             ;  Create a base for the left column
  614.             ;
  615.             wLeftBase = WIDGET_BASE(wTopRowBase, $
  616.                 /BASE_ALIGN_CENTER, /COLUMN)
  617.         
  618.                 ;  Create a droplist to select the the plot
  619.                 ;
  620.                 wPlotDropList = CW_BGROUP(wLeftBase, /COLUMN, $
  621.                     ['Velocity Field', 'Contour', $
  622.                     'Image', 'Shaded Surface', $
  623.                     'Show3 Plot', '4 Plots'], $
  624.                     /NO_RELEASE, $
  625.                     /EXCLUSIVE, UVALUE='PLOTLIST', SET_VALUE=5)
  626.  
  627.                 ;  Create the generate button that generates
  628.                 ;  a new data set
  629.                 ;
  630.                 wGenerateBase = WIDGET_BASE(wLeftBase, /COLUMN, $
  631.                     YPAD=20)
  632.  
  633.                     wGenerateButton = WIDGET_BUTTON(wGenerateBase, $
  634.                         VALUE='Generate New Data', UVALUE='GENERATE')
  635.  
  636.             ;  Create a base for the right column
  637.             ;
  638.             wRightBase = WIDGET_BASE(wTopRowBase, /COLUMN)
  639.  
  640.             ;  Create a draw widget
  641.             ;
  642.             drawXSize = 0.6*screenSize(0)
  643.             drawYSize = 0.8*drawXSize
  644.             wAreaDraw = WIDGET_DRAW(wRightBase, XSIZE=drawXSize,  $
  645.                 YSIZE=drawYSize, RETAIN=2)
  646.  
  647.         ;  Create tips texts.
  648.         ;
  649.         wStatusBase = WIDGET_BASE(wTopBase, MAP=0, /ROW)
  650.  
  651.             nWidgets = 2
  652.             wText = LONARR(nWidgets)
  653.             widTips, wStatusBase, sText.text, XSIZE=36, $
  654.                 YSIZE=3, NWIDGETS=nWidgets, wText
  655.  
  656.     ;  Realize the widget hierarchy.
  657.     ;
  658.     WIDGET_CONTROL, wTopBase, /REALIZE
  659.  
  660.     ;  Returns the top level base in the appTLB keyword.
  661.     ;
  662.     appTLB = wTopBase
  663.  
  664.     ;  Size the tips widgets.
  665.     ;
  666.     sizeTips, wTopBase, wText, wStatusBase
  667.  
  668.     WIDGET_CONTROL, wTopBase, SENSITIVE=0
  669.  
  670.     ; Determine the window value of plot window, wDraw1.
  671.     ;
  672.     WIDGET_CONTROL, wAreaDraw, GET_VALUE=drawWindowID
  673.  
  674.     WSET, drawWindowID
  675.     XYOUTS, 0.5, 0.5, /NORMAL, COLOR=maxImage+7, $ 
  676.         ' GENERATING DATA   PLEASE WAIT....', $
  677.         ALIGNMENT=0.5, SIZE=(!P.Charsize * 6.0), FONT=0
  678.  
  679.     ;  Generate a data set
  680.     ;
  681.     mat_Generate, xArray, yArray, height, xvelocity, yvelocity
  682.  
  683.  
  684.     ;  Create the plots and place each of them in a pixmap
  685.     ;
  686.     nPixmap = 7
  687.     pixmapArray = LONARR(nPixmap)
  688.     for i = 0, 5 do begin
  689.         Window, /FREE, XSIZE= drawXSize, YSIZE=drawYSize, /PIXMAP
  690.         pixmapArray(i) = !D.Window
  691.     endfor
  692.  
  693.     Window, /FREE, XSIZE= drawXSize/2, YSIZE=drawYSize/2, /PIXMAP
  694.     pixmapArray(6) = !D.Window
  695.  
  696.     mat_makePlot, pixmapArray, xArray, yArray, height, $
  697.          xVelocity, yVelocity, drawXSize, drawYSize, $
  698.          maxImage, plotPosition
  699.  
  700.     ;  Display the 4 plots screen
  701.     ;
  702.     WSET, drawWindowID
  703.     DEVICE, COPY=[ 0,0, drawXSize, drawYSize, 0, $
  704.          0, pixmapArray(5)]
  705.  
  706.     ;  Create the info structure
  707.     ;
  708.     sInfo={ colorTable: colorTable, $         ; color table to restore
  709.         DrawXSize: drawXSize, $               ; Window dimension
  710.         DrawYSize: drawYSize, $
  711.         PixmapArray: pixmapArray, $           ; Pixmap arrays
  712.         MaxImage: maxImage, $                 ; Number of color for plots
  713.         NPixmap: nPixmap, $                   ; Number of pixmap
  714.         PlotPosition: plotPosition, $         ; Plot position in the view
  715.         DrawWindowID: drawWindowID, $         ; Window ID
  716.         WAreaDraw: wAreaDraw, $               ; Draw window ID
  717.         WPlotDroplist: wPlotDroplist, $       ; Droplist ID
  718.         WHelpButton: wHelpButton, $           ; Help button ID
  719.         WQuitButton: wQuitButton, $           ; Quit button ID
  720.         WFileButton: wFileButton, $           ; File button ID
  721.         WTopBase: wTopBase, $                 ; Top level base ID
  722.         WLeftBase: wLeftBase, $               ; Left base ID
  723.         WStatusBase: wStatusBase, $           ; Statusbase ID
  724.         WGenerateButton: wGenerateButton, $   ; Generate button ID
  725.         groupBase: groupBase $                ; Base of Group Leader
  726.     }
  727.     
  728.     ;  Register the info structure in the user value of the top-level base
  729.     ;
  730.     WIDGET_CONTROL, wTopBase, SET_UVALUE=sInfo, /NO_COPY
  731.     
  732.     WIDGET_CONTROL, wTopBase, SENSITIVE=1
  733.  
  734.     ;  Destroy the starting up window.
  735.     ;
  736.     WIDGET_CONTROL, drawbase, /DESTROY
  737.  
  738.     ;  Map the top level base.
  739.     ;
  740.     WIDGET_CONTROL, wTopBase, MAP=1
  741.  
  742.     XMANAGER, "Template", wTopBase, $
  743.         /NO_BLOCK, $
  744.         EVENT_HANDLER="D_Matrix_Event", CLEANUP="D_Matrix_Cleanup"
  745.  
  746. end   ;  main procedure
  747.